package com.emapp.lccode.base;


import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

public class RecycleUtils {

    /**
     * 初始化水平的Recycle
     * @param recyclerView
     */
    public static void initHorizontalRecyle(RecyclerView recyclerView){

        LinearLayoutManager layoutManager = new LinearLayoutManager(BaseApplication.instance);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
    }
    public static void initHorizontalRecyleNoScrll(RecyclerView recyclerView){

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(BaseApplication.instance) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(linearLayoutManager);
    }

    /**
     * 初始化水平的Recycle
     * @param recyclerView
     */
    public static void initVerticalRecyle(RecyclerView recyclerView){

        LinearLayoutManager layoutManager = new LinearLayoutManager(BaseApplication.instance);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
    }
    public static void initVerticalRecyleNoScrll(RecyclerView recyclerView){

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(BaseApplication.instance) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
    }
    /**
     * 初始瀑布流平的Recycle
     * @param recyclerView
     */
    public static void initGridRecyle(RecyclerView recyclerView, int spanCount){
       // GridLayoutManager layoutManager =new GridLayoutManager(BaseApplication.getInstance(),spanCount,GridLayoutManager.VERTICAL,false);
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL);
//        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
//            @Override
//            public int getSpanSize(int position) {
//                // 如果是空布局，让它占满一行
//                if (mAdapter.isEmptyPosition(position)) {
//                    return layoutManager.getSpanCount();
//                }
//                return 1;
//            }
//        });
        recyclerView.setLayoutManager(layoutManager);
    }
    /**
     * 初始瀑布流平的Recycle
     * @param recyclerView
     */
    public static void initGridRecyleNoScroll(RecyclerView recyclerView, int spanCount){

        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        recyclerView.setLayoutManager(layoutManager);
    }
}
